package com.cs.study.homework._0308;

public class Demo5 {
    public static final Object OBJECT = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (OBJECT) {
                for (int i = 1; i <= 7; i++) {
                    OBJECT.notify();
                    System.out.print(i);
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    OBJECT.notify();
                }
            }
        }, "T1").start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        new Thread(() -> {
            synchronized (OBJECT) {
                for (char i = 'A'; i <= 'G'; i++) {
                    OBJECT.notify();
                    System.out.print(i);
                    try {
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    OBJECT.notify();
                }
            }
        }, "T2").start();
    }
}

